package org.example.demo.apiv2.sql;

import cn.hutool.core.collection.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.schema.Column;
import org.example.demo.apiv2.constant.CommonConstant;
import org.example.demo.apiv2.entity.FieldEntity;
import org.example.demo.apiv2.entity.GroupEntity;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class GroupParser {

    /**
     * 构造jsqlparser的Column对象集合
     *
     * @param groupEntityList
     * @return
     */
    public static List<Column> getGroupByColumnList(List<GroupEntity> groupEntityList) {
        if (CollectionUtil.isEmpty(groupEntityList)) {
            return new ArrayList<>();
        }
        List<Column> columnList = new ArrayList<>();
        for (GroupEntity groupEntity : groupEntityList) {
            FieldEntity field = groupEntity.getField();
            Column column = FieldParser.getColumn(field.getTable(), field.getTableAlias(), field.getColName());
            columnList.add(column);
        }
        return columnList;
    }
}
